$(function(){
	getClassInfo();
	getClassP();
})
var baseurl = 'http://kt.zhangzhengjiang.top/api/';
var static_url = 'http://kt.zhangzhengjiang.top/';
//获取url参数
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}
//获取课程详情页
function getClassInfo(){
	var kid = getQueryVariable('kid');
	$.ajax({
		url:baseurl+'index/getClassDetail',
		type:'post',
		data:{kid:kid},
		success:function(result){
			if(result.code == 1){
				var juese = window.localStorage.getItem('juese');
				var data = result.data;
				console.log(data);
				$('.title').html(data.title);
				$('#content').html(data.content);
				$('#detail').html(data.content);
				$('#price').html(data.price);
				$('#payprice').html(data.price);
				$('#pay_num').html(data.pay_num);
				$('#ketang_id').html(data.id);
				$('#teacher_avatar').attr('src',static_url+data.teacher.image);
				$('#teacher_name').html(data.teacher.name);
				$('#teacher_bianhao').html(data.teacher.bianhao);
				$('#teacherid').val(data.teacher.id);
				$('#fmt').css({
				  "background-image":"url("+static_url+data.images+")",
				  "background-repeat":"no-repeat",
				  "background-size":"100%"
				 })
				var curriculum_list  = data.curriculum_list;
				var curriculum_html = '';
				for (var i = 0; i < curriculum_list.length; i++) {
					if(curriculum_list[i].is_st == 1 && juese==1){
						curriculum_html+='<a href="#" onclick="goPay()">';
					}else{
						curriculum_html+='<a href="classRedio.html?rid='+curriculum_list[i].id+'">';
					}
						curriculum_html+='<li class="aui-list-item aui-padded-l-0 aui-border-b-0 aui-list-item-middle  aui-background-white">';
							curriculum_html+='<div class="aui-media-list-item-inner" style="align-items: center;">';
							var num = parseInt(i)+parseInt(1);
								curriculum_html+='<span class="aui-margin-r-15 aui-text-gray">'+num+'</span>';
								curriculum_html+='<div class="aui-list-item-media wechat-avatar aui-list-media-img" style="width: 4rem;">';
									curriculum_html+='<img src="'+static_url+curriculum_list[i].image+'" class="aui-border-radius">';
								curriculum_html+='</div>';
								curriculum_html+='<div class="aui-list-item-inner aui-padded-l-10" style="height: 4rem;">';
									curriculum_html+='<p class="aui-text-gray aui-font-size-16 aui-font-weight">'+curriculum_list[i].name+'</p>';
									curriculum_html+='<p class="aui-margin-t-5 aui-font-size-14">已有30w+人试听</p>';
								curriculum_html+='</div>';
								curriculum_html+='<div class="aui-text-default aui-margin-t-5">';
								if(curriculum_list[i].is_st == 1){
									
								}else if(curriculum_list[i].is_st == 1){
									curriculum_html+='<span class="aui-try-radio aui-try-before">试听</span>';
								}
									
								curriculum_html+='</div>';
							curriculum_html+='</div>';
						curriculum_html+='</li>';
					curriculum_html+='</a>';
				}
				$('#curriculum').html(curriculum_html);
			}
		}
	});
}
//
function goToTeacher(){
	var tid = $('#teacherid').val();
	window.location.href="teacherDetail.html?tid="+tid;
}
//获取评论
function getClassP(){
	var kid = getQueryVariable('kid');
	$.ajax({
		url:baseurl+'index/getClassPl',
		type:'post',
		data:{kid:kid},
		success:function(result){
			if(result.code == 1){
				var data = result.data;
				var html = '';
				for (var i = 0; i < data.length; i++) {
					html +='<li>';
						html +='<div class="aui-lesson-uint aui-clear-both aui-width-one" style="display: flex;">';
							html +='<img src="'+static_url+data[i].avatar+'" alt="" class="aui-user-write aui-pull-left">';
							html +='<div class="aui-pull-left aui-width-one">';
								html +='<div class="aui-unit-title">'+data[i].content+' </div>';
								// html +='<div class="aui-font-size-12 aui-margin-b-5">5星</div>';
								html +='<div class="aui-font-size-12 aui-clear-both">'+data[i].createtime;
									html +='<span class="aui-pull-right" onclick="jubao()"><i class="aui-iconfont aui-icon-info"></i> 举报</span>';
								html +='</div>';
							html +='</div>';
						html +='</div>';
						
					html +='</li>';
				}
				$('#pllist').html(html);
			}
		}
	})
}
//发表评论
function pinglun(){
	var ketang_id = getQueryVariable('kid');;
	var content = $('#plcontent').val();
	var uid = window.localStorage.getItem('uid');
	$.ajax({
		url:baseurl+'index/addContentClass',
		type:'post',
		data:{ketang_id:ketang_id,content:content,uid:uid},
		success:function(result){
			if(result.code == 1){
				layer.open({
				   content:result.msg
				   ,skin: 'msg'
				   ,time: 2 //2秒后自动关闭
				 });
				 // setTimeout(function(){
					//  location.href="../classLists.html?kid="+ketang_id;
				 // },2000);
				 $('.hidde').hide();
				 getClassP();
				 
			}
		}
	})
}
function jubao(){
	 layer.open({
	    content: '举报成功，感谢您维护互联网安全！'
	    ,skin: 'msg'
	    ,time: 2 //2秒后自动关闭
	  });
}
function goPay(){
	layer.open({
	   content: '请您先购买课程'
	   ,skin: 'msg'
	   ,time: 2 //2秒后自动关闭
	 });
}
//支付宝支付
function goToAlipay(){
		layer.open({
		   content: '敬请期待'
		   ,skin: 'msg'
		   ,time: 2 //2秒后自动关闭
		 });		
}
//微信支付
function goToWxpay(){
	layer.open({
	   content: '敬请期待'
	   ,skin: 'msg'
	   ,time: 2 //2秒后自动关闭
	 });
}